*** Replication files for: "The Local Costs of Moving: How Residential Moves Weaken Local Engagement"
*** Hans Lueders
*** Comparative Political Studies
*** September 2025





*----------------------------------------------*
*** Extract relevant variables from raw data ***
*----------------------------------------------*

*** 1. pgen data ***
*------------------*

*** load 
use $soep37/pgen, clear

*** code variables
* German nationality
gen german = .
replace german = 1 if pgnation == 1
replace german = 0 if pgnation > 1 & pgnation != .

* Marital status
gen marstat = pgfamstd if pgfamstd > 0 & pgfamstd != .
recode marstat (3=1) (1=2) (2=3) (4=3) (5=4) (6=2) (7=2) (8=3)
label define marstat 1 "single" 2 "married or same-sex union" ///
	3 "separated or divorced" 4 "widowed"
label value marstat marstat

* Education 1: Years of education overall
gen educ_years = pgbilzeit if pgbilzeit > 0 & pgbilzeit != .

* Education 2: Years of education, grouped
gen educ_years_class = .
replace educ_years_class = 1 if educ_years == 7 | educ_years == 8.5 | educ_years == 9
replace educ_years_class = 2 if educ_years == 10 | educ_years == 10.5
replace educ_years_class = 3 if educ_years == 11 | educ_years == 11.5 | educ_years == 12
replace educ_years_class = 4 if educ_years == 13 | educ_years == 13.5 | educ_years == 14 | educ_years == 14.5
replace educ_years_class = 5 if educ_years == 15 | educ_years == 16 | educ_years == 17
replace educ_years_class = 6 if educ_years == 18
label define educ_years_class 1 "-9 years" 2 "10 years" 3 "11-12 years" 4 "13-14 years" 5 "15-17 years" 6 "18+ years"
label value educ_years_class educ_years_class

* Education 3: Schulabschluss
gen educ_school = pgpsbil if pgpsbil > 0 & pgpsbil != . 
label define educ_school 1 "Hauptschulabschluss" 2 "Realschulabschluss" ///
	3 "Fachhochschulreife" 4 "Abitur" 5 "Anderer Abschluss" ///
	6 "Ohne Abschluss verlassen" 7 "Noch kein Abschluss" 8 "No school attended"
label value educ_school educ_school	

gen abitur = .
replace abitur = 1 if educ_school == 4
replace abitur = 0 if educ_school != 4 & educ_school != .

* Education 4: college degree
gen educ_college = pgpbbil02 if pgpbbil02 != .
recode educ_college (-2=0) (-1=.) (1=1) (2=2) (3=3) (4=1) (5=2) (6=2) (7=3) (8=2) (9=1) (10=1)
label define educ_college 0 "None" 1 "Technical College" 2 "University" 3 "degree abroad"
label value educ_college educ_college

gen college = .
replace college = 1 if educ_college >= 1 & educ_college <= 3
replace college = 0 if educ_college == 0

* Labor force status
gen lfs = pglfs if pglfs > 0 & pglfs != .
recode lfs (11=1) (12=1) (6=2) (3=3) (2=4) (4=5) (5=5) (8=6) (9=6) (10=6) (1=6) (13=6) 
label define lfs 1 "working" 2 "unemployed" 3 "education or training" 4 "retired" ///
	5 "not working due to specific reasons" 6 "not working"
label value lfs lfs


*** select variables
soepkeep pid syear german marstat educ* abitur college lfs

*** save
save $mydata/hlueders/CPS_pgen_select.dta, replace



*** 2. pequiv data ***
*--------------------*

*** load data
use $soep37/pequiv, clear

*** code variables
* Age
gen age = d11101 if d11101 >= 0

* age groups
gen agegroup = . 
replace agegroup = 1 if age <= 24
replace agegroup = 2 if age > 24 & age <= 29
replace agegroup = 3 if age > 29 & age <= 34
replace agegroup = 4 if age > 34 & age <= 39
replace agegroup = 5 if age > 39 & age <= 44
replace agegroup = 6 if age > 44 & age <= 49
replace agegroup = 7 if age > 49 & age <= 54
replace agegroup = 8 if age > 54 & age <= 59
replace agegroup = 9 if age > 59 & age <= 64
replace agegroup = 10 if age > 64 & age <= 69
replace agegroup = 11 if age > 69 & age <= 74
replace agegroup = 12 if age > 74 & age != .
label define agegroup 1 "18-24" 2 "25-29" 3 "30-34" 4 "35-39" 5 "40-44" 6 "45-49" ///
	7 "50-54" 8 "55-59" 9 "60-64" 10 "65-69" 11 "70-74" 12 "75+"
label value agegroup agegroup

* number of children
gen nchildren = d11107
gen nchildren_log = log(nchildren + 1)

* HH income
gen hhincome_pre = i11101 if i11101 >= 0
gen hhincome_post = i11102 if i11102 >= 0

* log HH income
gen hhincome_pre_log = log(hhincome_pre + 1)
gen hhincome_post_log = log(hhincome_post + 1)

* household size
gen hhsize = d11106
gen hhsize_log = log(hhsize)


*** select variables
soepkeep pid syear age agegroup hhincome_pre hhincome_pre_log ///
	hhincome_post hhincome_post_log ///
	hhsize hhsize_log nchildren nchildren_log w11103

*** save
save $mydata/hlueders/CPS_pequiv_select.dta, replace



*** 3. hl data ***
*----------------*

*** load data
use $soep37/hl, clear

*** code variables 
* rent or own the place?
gen owner = .
replace owner = 1 if hlf0001_h == 3
replace owner = 0 if hlf0001_h != 3 & hlf0001_h != .

*** select variables
soepkeep hid syear owner

*** save
save $mydata/hlueders/CPS_hl_select.dta, replace



*** 4. hbrutto data ***
*---------------------*

*** load data
use $soep37/hbrutto, clear

*** code variables
* address check
rename hader addressHH

*** select variables
soepkeep hid syear addressHH

*** save
save $mydata/hlueders/CPS_hbrutto_select.dta, replace



*** 5. kreise_l data ***
*----------------------*

*** load data
use $soep37/regionl, clear

*** select variables
soepkeep hid syear kkz_rek bula

*** save
save $mydata/hlueders/CPS_kreise_select.dta, replace



*** 6. pl data ***
*----------------*

*** load
use pid hid syear ///
	plh0007 plh0006 plh0333 plh0003 ///
	plj0040 plj0043 pli0097_h pli0096_h ///
	using $soep37/pl, clear

	


*** National engagement
* political interest
gen polinterest = plh0007 if plh0007 >0 & plh0007 != .
recode polinterest (4=1) (3=2) (2=3) (1=4)
label define polinterest 1 "none" 2 "weak" 3 "strong" 4 "very strong" 
label value polinterest polinterest

* voted in last federal election
gen vote_lastelection = .
replace vote_lastelection = 1 if plh0006 == 1 & syear == 2010
replace vote_lastelection = 0 if plh0006 == 2 & syear == 2010
replace vote_lastelection = 0 if plh0333 == 28 & syear == 2014
replace vote_lastelection = 0 if plh0333 == 28 & syear == 2018
replace vote_lastelection = 1 if plh0333 >= 1 & plh0333 <= 27 & syear == 2014
replace vote_lastelection = 1 if plh0333 >= 30 & plh0333 <= 31 & syear == 2014
replace vote_lastelection = 1 if plh0333 >= 1 & plh0333 <= 27 & syear == 2018
replace vote_lastelection = 1 if plh0333 >= 30 & plh0333 <= 31 & syear == 2018

* would vote next Sunday (next election)
gen vote_nextsunday = plh0003 if plh0003 >= 0 & plh0003 < 6
recode vote_nextsunday (1=5) (2=4) (3=3) (4=2) (5=1)
label define vote_nextsunday 1 "definitely not" 2 "probably not" 3 "maybe" 4 "probably" 5 " definitely"
label value vote_nextsunday vote_nextsunday



*** Local engagement
* local attachments
gen ties = plj0040 if plj0040 > 0
replace ties = plj0043 if (syear == 2009 | syear == 2014 | syear == 2019) & plj0043 >=0
recode ties (1=4) (2=3) (3=2) (4=1)

* participate local politics
gen activism_localpolitics = pli0097_h if pli0097_h > 0 & pli0097_h != .
recode activism_localpolitics (5=1) (4=2) (3=3) (2=4) (1=4) (6=1) (7=3) (8=4)

* volunteer
gen activism_volunteer = pli0096_h if pli0096_h > 0 & pli0096_h != .
recode activism_volunteer (5=1) (4=2) (3=3) (2=4) (1=4) (6=1) (7=3) (8=4)
 

*** select variables
soepkeep pid hid syear polinterest vote_lastelection vote_nextsunday ///
	ties activism_localpolitics activism_volunteer
	
	
	
	
*** 7. Merge datasets together ***
*--------------------------------*

*** merger
* pgen
merge 1:1 pid syear using $mydata/hlueders/CPS_pgen_select
soepdrop if _m==2
soepdrop _m

* pequiv
merge 1:1 pid syear using $mydata/hlueders/CPS_pequiv_select
soepdrop if _m==2
soepdrop _m

* hl
merge m:1 hid syear using $mydata/hlueders/CPS_hl_select
soepdrop if _m==2
soepdrop _m

* hbrutto
merge m:1 hid syear using $mydata/hlueders/CPS_hbrutto_select
soepdrop if _m==2
soepdrop _m

*** merge with Kreis data set (long)
merge m:1 hid syear using $mydata/hlueders/CPS_kreise_select
soepdrop if _m==2
soepdrop _m	



*** save
save $mydata/hlueders/CPS_replicationdata_working.dta, replace






*-------------------------------------------*
*** add federal election turnout averages ***
*-------------------------------------------*	

*** load
use $mydata/hlueders/CPS_replicationdata_working.dta, clear

	
*** code BT turnout averages
gen BT_turnout = .

replace BT_turnout = 0.705404 if kkz_rek == 1001
replace BT_turnout = 0.7426122 if kkz_rek == 1002
replace BT_turnout = 0.7138528 if kkz_rek == 1003
replace BT_turnout = 0.6896393 if kkz_rek == 1004
replace BT_turnout = 0.7367735 if kkz_rek == 1051
replace BT_turnout = 0.7798167 if kkz_rek == 1053
replace BT_turnout = 0.7546465 if kkz_rek == 1054
replace BT_turnout = 0.7629737 if kkz_rek == 1055
replace BT_turnout = 0.7915063 if kkz_rek == 1056
replace BT_turnout = 0.8031744 if kkz_rek == 1057
replace BT_turnout = 0.786793 if kkz_rek == 1058
replace BT_turnout = 0.7730809 if kkz_rek == 1059
replace BT_turnout = 0.7738485 if kkz_rek == 1060
replace BT_turnout = 0.7607802 if kkz_rek == 1061
replace BT_turnout = 0.806502 if kkz_rek == 1062
replace BT_turnout = 0.7493699 if kkz_rek == 2000
replace BT_turnout = 0.765913 if kkz_rek == 3101
replace BT_turnout = 0.7305452 if kkz_rek == 3102
replace BT_turnout = 0.7425801 if kkz_rek == 3103
replace BT_turnout = 0.7757172 if kkz_rek == 3151
replace BT_turnout = 0.7496728 if kkz_rek == 3153
replace BT_turnout = 0.7571442 if kkz_rek == 3154
replace BT_turnout = 0.7656884 if kkz_rek == 3155
replace BT_turnout = 0.7832099 if kkz_rek == 3157
replace BT_turnout = 0.7974219 if kkz_rek == 3158
replace BT_turnout = 0.7686642 if kkz_rek == 3159
replace BT_turnout = 0.7774661 if kkz_rek == 3241
replace BT_turnout = 0.7686718 if kkz_rek == 3251
replace BT_turnout = 0.7552658 if kkz_rek == 3252
replace BT_turnout = 0.7848678 if kkz_rek == 3254
replace BT_turnout = 0.7630953 if kkz_rek == 3255
replace BT_turnout = 0.7395834 if kkz_rek == 3256
replace BT_turnout = 0.7720539 if kkz_rek == 3257
replace BT_turnout = 0.7567837 if kkz_rek == 3351
replace BT_turnout = 0.7598051 if kkz_rek == 3352
replace BT_turnout = 0.8111042 if kkz_rek == 3353
replace BT_turnout = 0.7495714 if kkz_rek == 3354
replace BT_turnout = 0.7800248 if kkz_rek == 3355
replace BT_turnout = 0.7832201 if kkz_rek == 3356
replace BT_turnout = 0.7686324 if kkz_rek == 3357
replace BT_turnout = 0.7570309 if kkz_rek == 3358
replace BT_turnout = 0.7674531 if kkz_rek == 3359
replace BT_turnout = 0.7663283 if kkz_rek == 3360
replace BT_turnout = 0.7773961 if kkz_rek == 3361
replace BT_turnout = 0.7143272 if kkz_rek == 3401
replace BT_turnout = 0.7150139 if kkz_rek == 3402
replace BT_turnout = 0.76923 if kkz_rek == 3403
replace BT_turnout = 0.7555742 if kkz_rek == 3404
replace BT_turnout = 0.717032 if kkz_rek == 3405
replace BT_turnout = 0.7689641 if kkz_rek == 3451
replace BT_turnout = 0.7507727 if kkz_rek == 3452
replace BT_turnout = 0.731182 if kkz_rek == 3453
replace BT_turnout = 0.7738231 if kkz_rek == 3454
replace BT_turnout = 0.7622948 if kkz_rek == 3455
replace BT_turnout = 0.7749647 if kkz_rek == 3456
replace BT_turnout = 0.7443727 if kkz_rek == 3457
replace BT_turnout = 0.7830288 if kkz_rek == 3458
replace BT_turnout = 0.7780232 if kkz_rek == 3459
replace BT_turnout = 0.7666308 if kkz_rek == 3460
replace BT_turnout = 0.7335116 if kkz_rek == 3461
replace BT_turnout = 0.7239708 if kkz_rek == 3462
replace BT_turnout = 0.7386335 if kkz_rek == 4011
replace BT_turnout = 0.6811662 if kkz_rek == 4012
replace BT_turnout = 0.7558531 if kkz_rek == 5111
replace BT_turnout = 0.7038024 if kkz_rek == 5112
replace BT_turnout = 0.7403661 if kkz_rek == 5113
replace BT_turnout = 0.7208297 if kkz_rek == 5114
replace BT_turnout = 0.692626 if kkz_rek == 5116
replace BT_turnout = 0.7779409 if kkz_rek == 5117
replace BT_turnout = 0.7278101 if kkz_rek == 5119
replace BT_turnout = 0.7248926 if kkz_rek == 5120
replace BT_turnout = 0.7391955 if kkz_rek == 5122
replace BT_turnout = 0.730379 if kkz_rek == 5124
replace BT_turnout = 0.7492986 if kkz_rek == 5154
replace BT_turnout = 0.7755718 if kkz_rek == 5158
replace BT_turnout = 0.7721847 if kkz_rek == 5162
replace BT_turnout = 0.7621441 if kkz_rek == 5166
replace BT_turnout = 0.7712008 if kkz_rek == 5170
replace BT_turnout = 0.7947291 if kkz_rek == 5314
replace BT_turnout = 0.743909 if kkz_rek == 5315
replace BT_turnout = 0.7521228 if kkz_rek == 5316
replace BT_turnout = 0.751151 if kkz_rek == 5334
replace BT_turnout = 0.7578715 if kkz_rek == 5358
replace BT_turnout = 0.7716514 if kkz_rek == 5362
replace BT_turnout = 0.7481954 if kkz_rek == 5366
replace BT_turnout = 0.7477351 if kkz_rek == 5370
replace BT_turnout = 0.7537568 if kkz_rek == 5374
replace BT_turnout = 0.8057655 if kkz_rek == 5378
replace BT_turnout = 0.7839342 if kkz_rek == 5382
replace BT_turnout = 0.7558243 if kkz_rek == 5512
replace BT_turnout = 0.6938435 if kkz_rek == 5513
replace BT_turnout = 0.8131711 if kkz_rek == 5515
replace BT_turnout = 0.7792428 if kkz_rek == 5554
replace BT_turnout = 0.8074552 if kkz_rek == 5558
replace BT_turnout = 0.7502197 if kkz_rek == 5562
replace BT_turnout = 0.7824257 if kkz_rek == 5566
replace BT_turnout = 0.7834132 if kkz_rek == 5570
replace BT_turnout = 0.7651544 if kkz_rek == 5711
replace BT_turnout = 0.7648869 if kkz_rek == 5754
replace BT_turnout = 0.7517149 if kkz_rek == 5758
replace BT_turnout = 0.7755637 if kkz_rek == 5762
replace BT_turnout = 0.7664891 if kkz_rek == 5766
replace BT_turnout = 0.7462149 if kkz_rek == 5770
replace BT_turnout = 0.752524 if kkz_rek == 5774
replace BT_turnout = 0.7565456 if kkz_rek == 5911
replace BT_turnout = 0.7264237 if kkz_rek == 5913
replace BT_turnout = 0.7150085 if kkz_rek == 5914
replace BT_turnout = 0.7310595 if kkz_rek == 5915
replace BT_turnout = 0.7178468 if kkz_rek == 5916
replace BT_turnout = 0.7686075 if kkz_rek == 5954
replace BT_turnout = 0.7674295 if kkz_rek == 5958
replace BT_turnout = 0.7314157 if kkz_rek == 5962
replace BT_turnout = 0.769252 if kkz_rek == 5966
replace BT_turnout = 0.7593704 if kkz_rek == 5970
replace BT_turnout = 0.7546183 if kkz_rek == 5974
replace BT_turnout = 0.7621255 if kkz_rek == 5978
replace BT_turnout = 0.7697887 if kkz_rek == 6411
replace BT_turnout = 0.74054 if kkz_rek == 6412
replace BT_turnout = 0.6891176 if kkz_rek == 6413
replace BT_turnout = 0.7344945 if kkz_rek == 6414
replace BT_turnout = 0.7748474 if kkz_rek == 6431
replace BT_turnout = 0.7901694 if kkz_rek == 6432
replace BT_turnout = 0.7698353 if kkz_rek == 6433
replace BT_turnout = 0.8157278 if kkz_rek == 6434
replace BT_turnout = 0.7632406 if kkz_rek == 6435
replace BT_turnout = 0.8131422 if kkz_rek == 6436
replace BT_turnout = 0.7599464 if kkz_rek == 6437
replace BT_turnout = 0.7836244 if kkz_rek == 6438
replace BT_turnout = 0.7991101 if kkz_rek == 6439
replace BT_turnout = 0.7720873 if kkz_rek == 6440
replace BT_turnout = 0.7610227 if kkz_rek == 6531
replace BT_turnout = 0.7263637 if kkz_rek == 6532
replace BT_turnout = 0.7505842 if kkz_rek == 6533
replace BT_turnout = 0.7591367 if kkz_rek == 6534
replace BT_turnout = 0.7583357 if kkz_rek == 6535
replace BT_turnout = 0.7260252 if kkz_rek == 6611
replace BT_turnout = 0.7733412 if kkz_rek == 6631
replace BT_turnout = 0.7635739 if kkz_rek == 6632
replace BT_turnout = 0.7905044 if kkz_rek == 6633
replace BT_turnout = 0.7800732 if kkz_rek == 6634
replace BT_turnout = 0.7443874 if kkz_rek == 6635
replace BT_turnout = 0.7651734 if kkz_rek == 6636
replace BT_turnout = 0.7341433 if kkz_rek == 7111
replace BT_turnout = 0.7811815 if kkz_rek == 7131
replace BT_turnout = 0.7482955 if kkz_rek == 7132
replace BT_turnout = 0.75692 if kkz_rek == 7133
replace BT_turnout = 0.7147878 if kkz_rek == 7134
replace BT_turnout = 0.7774053 if kkz_rek == 7135
replace BT_turnout = 0.7523988 if kkz_rek == 7137
replace BT_turnout = 0.7606341 if kkz_rek == 7138
replace BT_turnout = 0.7691271 if kkz_rek == 7140
replace BT_turnout = 0.7618013 if kkz_rek == 7141
replace BT_turnout = 0.767259 if kkz_rek == 7143
replace BT_turnout = 0.7183827 if kkz_rek == 7211
replace BT_turnout = 0.7592845 if kkz_rek == 7231
replace BT_turnout = 0.7541773 if kkz_rek == 7232
replace BT_turnout = 0.7610871 if kkz_rek == 7233
replace BT_turnout = 0.7907246 if kkz_rek == 7235
replace BT_turnout = 0.7328324 if kkz_rek == 7311
replace BT_turnout = 0.6914334 if kkz_rek == 7312
replace BT_turnout = 0.7457563 if kkz_rek == 7313
replace BT_turnout = 0.7088013 if kkz_rek == 7314
replace BT_turnout = 0.7855452 if kkz_rek == 7315
replace BT_turnout = 0.7740668 if kkz_rek == 7316
replace BT_turnout = 0.6793633 if kkz_rek == 7317
replace BT_turnout = 0.7447454 if kkz_rek == 7318
replace BT_turnout = 0.7111425 if kkz_rek == 7319
replace BT_turnout = 0.7040855 if kkz_rek == 7320
replace BT_turnout = 0.7850553 if kkz_rek == 7331
replace BT_turnout = 0.7935183 if kkz_rek == 7332
replace BT_turnout = 0.7488217 if kkz_rek == 7333
replace BT_turnout = 0.7681472 if kkz_rek == 7334
replace BT_turnout = 0.7657287 if kkz_rek == 7335
replace BT_turnout = 0.7554981 if kkz_rek == 7336
replace BT_turnout = 0.7922505 if kkz_rek == 7337
replace BT_turnout = 0.8120959 if kkz_rek == 7338
replace BT_turnout = 0.810749 if kkz_rek == 7339
replace BT_turnout = 0.7939361 if kkz_rek == 7340
replace BT_turnout = 0.7814863 if kkz_rek == 8111
replace BT_turnout = 0.7966431 if kkz_rek == 8115
replace BT_turnout = 0.7994082 if kkz_rek == 8116
replace BT_turnout = 0.7663211 if kkz_rek == 8117
replace BT_turnout = 0.7984489 if kkz_rek == 8118
replace BT_turnout = 0.7849361 if kkz_rek == 8119
replace BT_turnout = 0.7209144 if kkz_rek == 8121
replace BT_turnout = 0.7787783 if kkz_rek == 8125
replace BT_turnout = 0.7552961 if kkz_rek == 8126
replace BT_turnout = 0.7278451 if kkz_rek == 8127
replace BT_turnout = 0.7705595 if kkz_rek == 8128
replace BT_turnout = 0.7532598 if kkz_rek == 8135
replace BT_turnout = 0.764399 if kkz_rek == 8136
replace BT_turnout = 0.7501011 if kkz_rek == 8211
replace BT_turnout = 0.7536404 if kkz_rek == 8212
replace BT_turnout = 0.7823719 if kkz_rek == 8215
replace BT_turnout = 0.7464781 if kkz_rek == 8216
replace BT_turnout = 0.7900738 if kkz_rek == 8221
replace BT_turnout = 0.7194574 if kkz_rek == 8222
replace BT_turnout = 0.7508442 if kkz_rek == 8225
replace BT_turnout = 0.7918566 if kkz_rek == 8226
replace BT_turnout = 0.691421 if kkz_rek == 8231
replace BT_turnout = 0.7691698 if kkz_rek == 8235
replace BT_turnout = 0.7893797 if kkz_rek == 8236
replace BT_turnout = 0.7496455 if kkz_rek == 8237
replace BT_turnout = 0.7827608 if kkz_rek == 8311
replace BT_turnout = 0.7908291 if kkz_rek == 8315
replace BT_turnout = 0.7744463 if kkz_rek == 8316
replace BT_turnout = 0.7368174 if kkz_rek == 8317
replace BT_turnout = 0.7529347 if kkz_rek == 8325
replace BT_turnout = 0.7466546 if kkz_rek == 8326
replace BT_turnout = 0.7502341 if kkz_rek == 8327
replace BT_turnout = 0.757688 if kkz_rek == 8335
replace BT_turnout = 0.7355487 if kkz_rek == 8336
replace BT_turnout = 0.7347013 if kkz_rek == 8337
replace BT_turnout = 0.7786956 if kkz_rek == 8415
replace BT_turnout = 0.8098905 if kkz_rek == 8416
replace BT_turnout = 0.7443653 if kkz_rek == 8417
replace BT_turnout = 0.7675426 if kkz_rek == 8421
replace BT_turnout = 0.79304 if kkz_rek == 8425
replace BT_turnout = 0.7726378 if kkz_rek == 8426
replace BT_turnout = 0.7828395 if kkz_rek == 8435
replace BT_turnout = 0.7651352 if kkz_rek == 8436
replace BT_turnout = 0.7524514 if kkz_rek == 8437


save $mydata/hlueders/CPS_replicationdata_working.dta, replace

** break **

use $mydata/hlueders/CPS_replicationdata_working.dta, clear

replace BT_turnout = 0.6840428 if kkz_rek == 9161
replace BT_turnout = 0.7606886 if kkz_rek == 9162
replace BT_turnout = 0.7048016 if kkz_rek == 9163
replace BT_turnout = 0.7309098 if kkz_rek == 9171
replace BT_turnout = 0.737117 if kkz_rek == 9172
replace BT_turnout = 0.7773911 if kkz_rek == 9173
replace BT_turnout = 0.791483 if kkz_rek == 9174
replace BT_turnout = 0.8175328 if kkz_rek == 9175
replace BT_turnout = 0.7972873 if kkz_rek == 9176
replace BT_turnout = 0.7773573 if kkz_rek == 9177
replace BT_turnout = 0.7829304 if kkz_rek == 9178
replace BT_turnout = 0.8056935 if kkz_rek == 9179
replace BT_turnout = 0.7690852 if kkz_rek == 9180
replace BT_turnout = 0.7919419 if kkz_rek == 9181
replace BT_turnout = 0.7839085 if kkz_rek == 9182
replace BT_turnout = 0.729885 if kkz_rek == 9183
replace BT_turnout = 0.8198327 if kkz_rek == 9184
replace BT_turnout = 0.7509973 if kkz_rek == 9185
replace BT_turnout = 0.7599114 if kkz_rek == 9186
replace BT_turnout = 0.7748305 if kkz_rek == 9187
replace BT_turnout = 0.8284464 if kkz_rek == 9188
replace BT_turnout = 0.7553037 if kkz_rek == 9189
replace BT_turnout = 0.7829456 if kkz_rek == 9190
replace BT_turnout = 0.7178337 if kkz_rek == 9261
replace BT_turnout = 0.6996819 if kkz_rek == 9262
replace BT_turnout = 0.6556013 if kkz_rek == 9263
replace BT_turnout = 0.6867876 if kkz_rek == 9271
replace BT_turnout = 0.6778223 if kkz_rek == 9272
replace BT_turnout = 0.7365601 if kkz_rek == 9273
replace BT_turnout = 0.7646909 if kkz_rek == 9274
replace BT_turnout = 0.6992554 if kkz_rek == 9275
replace BT_turnout = 0.6840634 if kkz_rek == 9276
replace BT_turnout = 0.7099159 if kkz_rek == 9277
replace BT_turnout = 0.7631352 if kkz_rek == 9278
replace BT_turnout = 0.7095307 if kkz_rek == 9279
replace BT_turnout = 0.6877044 if kkz_rek == 9361
replace BT_turnout = 0.7217204 if kkz_rek == 9362
replace BT_turnout = 0.6973756 if kkz_rek == 9363
replace BT_turnout = 0.7658216 if kkz_rek == 9371
replace BT_turnout = 0.7118661 if kkz_rek == 9372
replace BT_turnout = 0.7835047 if kkz_rek == 9373
replace BT_turnout = 0.7789649 if kkz_rek == 9374
replace BT_turnout = 0.7710292 if kkz_rek == 9375
replace BT_turnout = 0.7341778 if kkz_rek == 9376
replace BT_turnout = 0.7705643 if kkz_rek == 9377
replace BT_turnout = 0.7219658 if kkz_rek == 9461
replace BT_turnout = 0.712639 if kkz_rek == 9462
replace BT_turnout = 0.7209926 if kkz_rek == 9463
replace BT_turnout = 0.6970066 if kkz_rek == 9464
replace BT_turnout = 0.7842617 if kkz_rek == 9471
replace BT_turnout = 0.7784072 if kkz_rek == 9472
replace BT_turnout = 0.7676323 if kkz_rek == 9473
replace BT_turnout = 0.7920778 if kkz_rek == 9474
replace BT_turnout = 0.7618195 if kkz_rek == 9475
replace BT_turnout = 0.7579365 if kkz_rek == 9476
replace BT_turnout = 0.7606798 if kkz_rek == 9477
replace BT_turnout = 0.7559174 if kkz_rek == 9478
replace BT_turnout = 0.7317528 if kkz_rek == 9479
replace BT_turnout = 0.6928023 if kkz_rek == 9561
replace BT_turnout = 0.781981 if kkz_rek == 9562
replace BT_turnout = 0.7100069 if kkz_rek == 9563
replace BT_turnout = 0.7277556 if kkz_rek == 9564
replace BT_turnout = 0.75157 if kkz_rek == 9565
replace BT_turnout = 0.756179 if kkz_rek == 9571
replace BT_turnout = 0.8090281 if kkz_rek == 9572
replace BT_turnout = 0.8006604 if kkz_rek == 9573
replace BT_turnout = 0.7992879 if kkz_rek == 9574
replace BT_turnout = 0.7584896 if kkz_rek == 9575
replace BT_turnout = 0.7965868 if kkz_rek == 9576
replace BT_turnout = 0.7463651 if kkz_rek == 9577
replace BT_turnout = 0.7120917 if kkz_rek == 9661
replace BT_turnout = 0.6807203 if kkz_rek == 9662
replace BT_turnout = 0.7450677 if kkz_rek == 9663
replace BT_turnout = 0.790583 if kkz_rek == 9671
replace BT_turnout = 0.7680004 if kkz_rek == 9672
replace BT_turnout = 0.7698753 if kkz_rek == 9673
replace BT_turnout = 0.7817832 if kkz_rek == 9674
replace BT_turnout = 0.7673723 if kkz_rek == 9675
replace BT_turnout = 0.7730446 if kkz_rek == 9676
replace BT_turnout = 0.7865251 if kkz_rek == 9677
replace BT_turnout = 0.8007092 if kkz_rek == 9678
replace BT_turnout = 0.8187466 if kkz_rek == 9679
replace BT_turnout = 0.7042881 if kkz_rek == 9761
replace BT_turnout = 0.6952905 if kkz_rek == 9762
replace BT_turnout = 0.6938007 if kkz_rek == 9763
replace BT_turnout = 0.7140365 if kkz_rek == 9764
replace BT_turnout = 0.7862081 if kkz_rek == 9771
replace BT_turnout = 0.7708035 if kkz_rek == 9772
replace BT_turnout = 0.7358308 if kkz_rek == 9773
replace BT_turnout = 0.7261322 if kkz_rek == 9774
replace BT_turnout = 0.7481363 if kkz_rek == 9775
replace BT_turnout = 0.7584513 if kkz_rek == 9776
replace BT_turnout = 0.771623 if kkz_rek == 9777
replace BT_turnout = 0.7580229 if kkz_rek == 9778
replace BT_turnout = 0.7663031 if kkz_rek == 9779
replace BT_turnout = 0.780302 if kkz_rek == 9780
replace BT_turnout = 0.7410881 if kkz_rek == 10041
replace BT_turnout = 0.7750829 if kkz_rek == 10042
replace BT_turnout = 0.7546275 if kkz_rek == 10043
replace BT_turnout = 0.7704127 if kkz_rek == 10044
replace BT_turnout = 0.7812241 if kkz_rek == 10045
replace BT_turnout = 0.8097119 if kkz_rek == 10046
replace BT_turnout = 0.7479537 if kkz_rek == 11000
replace BT_turnout = 0.6418524 if kkz_rek == 12051
replace BT_turnout = 0.6899214 if kkz_rek == 12052
replace BT_turnout = 0.6831703 if kkz_rek == 12053
replace BT_turnout = 0.7608504 if kkz_rek == 12054
replace BT_turnout = 0.7151163 if kkz_rek == 12060
replace BT_turnout = 0.7461178 if kkz_rek == 12061
replace BT_turnout = 0.7198936 if kkz_rek == 12062
replace BT_turnout = 0.7200133 if kkz_rek == 12063
replace BT_turnout = 0.7145014 if kkz_rek == 12064
replace BT_turnout = 0.7283244 if kkz_rek == 12065
replace BT_turnout = 0.6937434 if kkz_rek == 12066
replace BT_turnout = 0.7167995 if kkz_rek == 12067
replace BT_turnout = 0.6673012 if kkz_rek == 12068
replace BT_turnout = 0.7575244 if kkz_rek == 12069
replace BT_turnout = 0.691462 if kkz_rek == 12070
replace BT_turnout = 0.7168441 if kkz_rek == 12071
replace BT_turnout = 0.7166286 if kkz_rek == 12072
replace BT_turnout = 0.6776733 if kkz_rek == 12073
replace BT_turnout = 0.6957315 if kkz_rek == 13003
replace BT_turnout = 0.7020898 if kkz_rek == 13004
replace BT_turnout = 0.6677127 if kkz_rek == 13071
replace BT_turnout = 0.6953374 if kkz_rek == 13072
replace BT_turnout = 0.6647114 if kkz_rek == 13073
replace BT_turnout = 0.677156 if kkz_rek == 13074
replace BT_turnout = 0.6664934 if kkz_rek == 13075
replace BT_turnout = 0.6922016 if kkz_rek == 13076
replace BT_turnout = 0.6961152 if kkz_rek == 14511
replace BT_turnout = 0.7004692 if kkz_rek == 14521
replace BT_turnout = 0.6981078 if kkz_rek == 14522
replace BT_turnout = 0.6897646 if kkz_rek == 14523
replace BT_turnout = 0.684515 if kkz_rek == 14524
replace BT_turnout = 0.7357227 if kkz_rek == 14612
replace BT_turnout = 0.7031913 if kkz_rek == 14625
replace BT_turnout = 0.6811097 if kkz_rek == 14626
replace BT_turnout = 0.7032029 if kkz_rek == 14627
replace BT_turnout = 0.712047 if kkz_rek == 14628
replace BT_turnout = 0.6969867 if kkz_rek == 14713
replace BT_turnout = 0.692628 if kkz_rek == 14729
replace BT_turnout = 0.6665347 if kkz_rek == 14730
replace BT_turnout = 0.6531634 if kkz_rek == 15001
replace BT_turnout = 0.6600658 if kkz_rek == 15002
replace BT_turnout = 0.6472597 if kkz_rek == 15003
replace BT_turnout = 0.6460826 if kkz_rek == 15081
replace BT_turnout = 0.6228551 if kkz_rek == 15082
replace BT_turnout = 0.6359743 if kkz_rek == 15083
replace BT_turnout = 0.6300703 if kkz_rek == 15084
replace BT_turnout = 0.6222077 if kkz_rek == 15085
replace BT_turnout = 0.6418045 if kkz_rek == 15086
replace BT_turnout = 0.6195506 if kkz_rek == 15087
replace BT_turnout = 0.6440179 if kkz_rek == 15088
replace BT_turnout = 0.6000611 if kkz_rek == 15089
replace BT_turnout = 0.6330116 if kkz_rek == 15090
replace BT_turnout = 0.6590493 if kkz_rek == 15091
replace BT_turnout = 0.7244151 if kkz_rek == 16051
replace BT_turnout = 0.7010053 if kkz_rek == 16052
replace BT_turnout = 0.756715 if kkz_rek == 16053
replace BT_turnout = 0.6973441 if kkz_rek == 16054
replace BT_turnout = 0.7312337 if kkz_rek == 16055
replace BT_turnout = 0.7040766 if kkz_rek == 16056
replace BT_turnout = 0.7504262 if kkz_rek == 16061
replace BT_turnout = 0.6955894 if kkz_rek == 16062
replace BT_turnout = 0.7180349 if kkz_rek == 16063
replace BT_turnout = 0.6992767 if kkz_rek == 16064
replace BT_turnout = 0.6869043 if kkz_rek == 16065
replace BT_turnout = 0.7002598 if kkz_rek == 16066
replace BT_turnout = 0.7114699 if kkz_rek == 16067
replace BT_turnout = 0.7033675 if kkz_rek == 16068
replace BT_turnout = 0.7054139 if kkz_rek == 16069
replace BT_turnout = 0.729592 if kkz_rek == 16070
replace BT_turnout = 0.7308562 if kkz_rek == 16071
replace BT_turnout = 0.6863804 if kkz_rek == 16072
replace BT_turnout = 0.7106448 if kkz_rek == 16073
replace BT_turnout = 0.7417912 if kkz_rek == 16074
replace BT_turnout = 0.7268371 if kkz_rek == 16075
replace BT_turnout = 0.7341097 if kkz_rek == 16076
replace BT_turnout = 0.687317 if kkz_rek == 16077


*** save
save $mydata/hlueders/CPS_replicationdata_working.dta, replace
	
	

	
*-------------------------------*
*** Further data manipulation ***
*-------------------------------*

*** load
use $mydata/hlueders/CPS_replicationdata_working.dta, clear


*** code instances of domestic migration
* any move: HH address change
gen move_addressHH = .
replace move_addressHH = 1 if addressHH >=1 & addressHH != 6 & addressHH != .
replace move_addressHH = 0 if addressHH <1 

* move across county boders
sort pid syear
by pid: gen kkz_rek_lag = kkz_rek[_n-1]
gen move_kreis = .
replace move_kreis = 0 if kkz_rek == kkz_rek_lag & kkz_rek !=. & kkz_rek_lag != . & kkz_rek >=1 & kkz_rek_lag >= 1
replace move_kreis = 1 if kkz_rek != kkz_rek_lag & kkz_rek !=. & kkz_rek_lag != . & kkz_rek >=1 & kkz_rek_lag >= 1

* move across state borders
sort pid syear
by pid: gen bula_lag = bula[_n-1]
gen move_land = .
replace move_land = 0 if bula == bula_lag & bula !=. & bula_lag != . & bula >=1 & bula_lag >= 1
replace move_land = 1 if bula != bula_lag & bula !=. & bula_lag != . & bula >=1 & bula_lag >= 1

* move across county borders within the same state
gen move_sameland = .
replace move_sameland = 0 if move_kreis == 0
replace move_sameland = 1 if move_kreis == 1 & move_land == 0


*** Number of moves included in the survey
* any move
bysort pid: egen moveTotal_addressHH = sum(move_addressHH)

* moves across county borders
bysort pid: egen moveTotal_kreis = sum(move_kreis)

* moves across state borders
bysort pid: egen moveTotal_land = sum(move_land)

* moves across county borders in the same state
bysort pid: egen moveTotal_sameland = sum(move_sameland)




*** years to / since migration
* identify years that respondents moved across Kreise 
gen move_kreis_year = syear if move_kreis == 1

* years since last move
sort pid syear
gen move_kreis_year_lastmove = move_kreis_year
by pid: replace move_kreis_year_lastmove = move_kreis_year_lastmove[_n-1] if move_kreis_year_lastmove == .
gen move_kreis_yearsince = syear - move_kreis_year_lastmove
replace move_kreis_yearsince = 0 if move_kreis != . & move_kreis_yearsince == .
soepdrop move_kreis_year_lastmove

* years to next move
gsort + pid - syear
gen move_kreis_year_nextmove = move_kreis_year
by pid: replace move_kreis_year_nextmove = move_kreis_year_nextmove[_n-1] if move_kreis_year_nextmove == .
gen move_kreis_yearsto = move_kreis_year_nextmove - syear
replace move_kreis_yearsto = 0 if move_kreis != . & move_kreis_yearsto == .
soepdrop move_kreis_year_nextmove

* year of first move
gen aux = syear if move_kreis == 1
bysort pid: egen move_kreis_firstyear = mean(aux)
replace move_kreis_firstyear = 0 if move_kreis_firstyear == .
soepdrop aux

* bottom- and top-code around +/- 10 years before/after move
replace move_kreis_yearsto = 10 if move_kreis_yearsto > 10 & move_kreis_yearsto != .
replace move_kreis_yearsince = 10 if move_kreis_yearsince > 10 & move_kreis_yearsince != .







*** Code years before/after a move by distance 1: any distance
* identify years with a move
gen year_move_addressHH = syear if move_addressHH == 1

* last year someone moved
gen year_move_addressHH_last = year_move_addressHH
sort pid syear
by pid: replace year_move_addressHH_last = year_move_addressHH_last[_n-1] if year_move_addressHH_last == .

* first year someone moved
by pid: egen year_move_addressHH_min = min(year_move_addressHH)

* code years before/after a move
gen aux2 = syear - year_move_addressHH_min
gen move_addressHH_prepost = 0
replace move_addressHH_prepost = 1 if aux2 >= -5 & aux2 <= -1
replace move_addressHH_prepost = 2 if aux2 == 0
replace move_addressHH_prepost = 3 if aux2 >= 1 & aux2 <= 5
replace move_addressHH_prepost = 4 if aux2 >= 6 & aux2 != .
label define move_addressHH_prepost 0 "baseline" 1 "1-5 pre" 2 "move" 3 "1-5 post" 4 "6+ post"
label value move_addressHH_prepost move_addressHH_prepost

soepdrop aux aux2

* recode to missing for everyone who has moved across counties at least once
replace move_addressHH_prepost = . if moveTotal_kreis != 0

* recode to missing for second move and later years
replace move_addressHH_prepost = . if moveTotal_addressHH > 1 & year_move_addressHH_last > year_move_addressHH_min & year_move_addressHH_last != . & year_move_addressHH_min != .






*** Code years before/after a move by distance 2: cross-county move
* identify years with a move
gen year_move_kreis = syear if move_kreis == 1

* last year someone moved
gen year_move_kreis_last = year_move_kreis
sort pid syear
by pid: replace year_move_kreis_last = year_move_kreis_last[_n-1] if year_move_kreis_last == .

* first year someone moved
by pid: egen year_move_kreis_min = min(year_move_kreis)

* code years before/after a move
gen aux2 = syear - year_move_kreis_min
gen move_kreis_prepost = 0
replace move_kreis_prepost = 1 if aux2 >= -5 & aux2 <= -1
replace move_kreis_prepost = 2 if aux2 == 0
replace move_kreis_prepost = 3 if aux2 >= 1 & aux2 <= 5
replace move_kreis_prepost = 4 if aux2 >= 6 & aux2 != .
label define move_kreis_prepost 0 "baseline" 1 "1-5 pre" 2 "move" 3 "1-5 post" 4 "6+ post"
label value move_kreis_prepost move_kreis_prepost

soepdrop aux aux2

* recode as missing in year of second move and later years
replace move_kreis_prepost = . if moveTotal_kreis > 1 & year_move_kreis_last > year_move_kreis_min & year_move_kreis_last != . & year_move_kreis_min != .








*** Code years before/after a move by distance 3: cross-county same-state move
* identify year with a move
gen year_move_sameland = syear if move_sameland == 1

* last year someone moved
gen year_move_sameland_last = year_move_sameland
sort pid syear
by pid: replace year_move_sameland_last = year_move_sameland_last[_n-1] if year_move_sameland_last == .

* first year someone moved
by pid: egen year_move_sameland_min = min(year_move_sameland)

* years before/after a move
gen aux2 = syear - year_move_sameland_min
gen move_sameland_prepost = 0
replace move_sameland_prepost = 1 if aux2 >= -5 & aux2 <= -1
replace move_sameland_prepost = 2 if aux2 == 0
replace move_sameland_prepost = 3 if aux2 >= 1 & aux2 <= 5
replace move_sameland_prepost = 4 if aux2 >= 6 & aux2 != .
label define move_sameland_prepost 0 "baseline" 1 "1-5 pre" 2 "move" 3 "1-5 post" 4 "6+ post"
label value move_sameland_prepost move_sameland_prepost

soepdrop aux aux2

* recode to missing for everyone who has moved across state borders
replace move_sameland_prepost = . if moveTotal_land != 0

* recode as missing in year of second move and later years
replace move_sameland_prepost = . if moveTotal_sameland > 1 & year_move_sameland_last > year_move_sameland_min & year_move_sameland_last != . & year_move_sameland_min != .




*** Code years before/after a move by distance 4: cross-Land move
* identify years with a move
gen year_move_land = syear if move_land == 1

* last year someone moved
gen year_move_land_last = year_move_land
sort pid syear
by pid: replace year_move_land_last = year_move_land_last[_n-1] if year_move_land_last == .

* first year someone moved
by pid: egen year_move_land_min = min(year_move_land)

* years before/after a move
gen aux2 = syear - year_move_land_min
gen move_land_prepost = 0
replace move_land_prepost = 1 if aux2 >= -5 & aux2 <= -1
replace move_land_prepost = 2 if aux2 == 0
replace move_land_prepost = 3 if aux2 >= 1 & aux2 <= 5
replace move_land_prepost = 4 if aux2 >= 6 & aux2 != .
label define move_land_prepost 0 "baseline" 1 "1-5 pre" 2 "move" 3 "1-5 post" 4 "6+ post"
label value move_land_prepost move_land_prepost

soepdrop aux aux2

* recode to missing for everyone who moved in the same state
replace move_land_prepost = . if moveTotal_sameland != 0 & moveTotal_sameland != .

* recode to missing in year of second move and later years
replace move_land_prepost = . if moveTotal_land > 1 & year_move_land_last > year_move_land_min & year_move_land_last != . & year_move_land_min != .


*** define period after a cross-county move
gen move_kreis_post = 0
replace move_kreis_post = 1 if syear >= year_move_kreis_min
label define move_kreis_post 0 "baseline" 1 "post-move"
label value move_kreis_post move_kreis_post

* recode this variable to missing for year of second move and later years
replace move_kreis_post = . if moveTotal_kreis > 1 & year_move_kreis_last > year_move_kreis_min & year_move_kreis_last != . & year_move_kreis_min != .








*** individual-level moderators
* define age cutoff: younger/older than 29
gen aux = age if year_move_kreis_min == syear
bysort pid: egen ageMove29 = mean(aux)

bysort pid: egen ageMedian29 = median(age)

gen age_old29 = .
replace age_old29 = 0 if ageMove29<= 29 | ageMedian29 <= 29
replace age_old29 = 1 if (ageMove29 > 29 & ageMove29 !=.) | (ageMedian29 > 29 & ageMedian29 !=. )
label define age_old29 0 "young" 1 "old"
label value age_old29 age_old29

soepdrop aux ageMove29 ageMedian29

* Abitur
sort pid syear
by pid: egen abiturSUM = mean(abitur)
replace abiturSUM = 1 if abiturSUM > 0 & abiturSUM != .
label define abiturSUM 0 "no" 1 "Abitur"
label value abiturSUM abiturSUM


* College degree
sort pid syear
by pid: egen collegeSUM = mean(college)
replace collegeSUM = 1 if collegeSUM > 0 & collegeSUM != .
label define collegeSUM 0 "no" 1 "College degree"
label value collegeSUM collegeSUM






*** code migration between places with varying federal turnout
* lag turnout
sort pid syear
by pid: gen BT_turnout_lag = BT_turnout[_n-1]

* difference 
gen BT_turnout_diff = BT_turnout - BT_turnout_lag if move_kreis == 1 & BT_turnout !=. & BT_turnout_lag != .

* identify movements between low and high areas: 1 SD
gen move_lowhigh_turnout1 = .
replace move_lowhigh_turnout1 = 1 if abs(BT_turnout_diff) < 0.0408333
replace move_lowhigh_turnout1 = 2 if BT_turnout_diff >= 0.0408333 & BT_turnout_diff != .
replace move_lowhigh_turnout1 = 3 if BT_turnout_diff <= -0.0408333 & BT_turnout_diff != .

soepdrop BT_turnout_diff

* create classes: 1 SD
bysort pid: egen aux = mean(move_lowhigh_turnout1)
gen migrant_lowhigh_turnout1 = 0
replace migrant_lowhigh_turnout1 = 1 if aux == 2
replace migrant_lowhigh_turnout1 = 2 if aux == 3
label define migrant_lowhigh_turnout1 0 "baseline" 1 "l-h" 2 "h-l"
label value migrant_lowhigh_turnout1 migrant_lowhigh_turnout1
soepdrop aux



*** code migration between places with varying local attachments
* code average ties
bysort kkz_rek: egen tiesAVG = mean(ties)

* lag variable
sort pid syear
by pid: gen tiesAVG_lag = tiesAVG[_n-1]

* difference 
gen diff = tiesAVG - tiesAVG_lag if move_kreis == 1 & tiesAVG !=. & tiesAVG_lag != .

* identify movements between low and high areas: 1 SD
gen move_lowhigh_ties1 = .
replace move_lowhigh_ties1 = 1 if abs(diff) < 0.1270113
replace move_lowhigh_ties1 = 2 if diff >= 0.1270113 & diff != .
replace move_lowhigh_ties1 = 3 if diff <= -0.1270113 & diff != .

soepdrop diff

* create classes: 1 SD
bysort pid: egen aux = mean(move_lowhigh_ties1)
gen migrant_lowhigh_ties1 = 0
replace migrant_lowhigh_ties1 = 1 if aux == 2
replace migrant_lowhigh_ties1 = 2 if aux == 3
label define migrant_lowhigh_ties1 0 "baseline" 1 "l-h" 2 "h-l"
label value migrant_lowhigh_ties1 migrant_lowhigh_ties1
soepdrop aux





*** Remove respondents who are not German
soepkeep if german == 1



*** save
save $mydata/hlueders/CPS_replicationdata.dta, replace

















*-------------------------------------------------------------*
*** Figure 1: Changes in engagement before and after a move ***
*-------------------------------------------------------------*

*** load data
use $mydata/hlueders/CPS_replicationdata.dta, clear


*** National engagement
eststo clear
eststo: quietly: reghdfe polinterest i.move_kreis_yearsto move_kreis i.move_kreis_yearsince ///
	i.agegroup i.marstat i.educ_years_class i.lfs hhsize_log nchildren_log hhincome_post_log owner [aweight=w11103], a(pid kkz_rek syear) vce(cluster hid)
eststo: quietly: reghdfe vote_lastelection i.move_kreis_yearsto move_kreis i.move_kreis_yearsince ///
	i.agegroup i.marstat i.educ_years_class i.lfs hhsize_log nchildren_log hhincome_post_log owner [aweight=w11103], a(pid kkz_rek syear) vce(cluster hid)
eststo: quietly: reghdfe vote_nextsunday i.move_kreis_yearsto move_kreis i.move_kreis_yearsince ///
	i.agegroup i.marstat i.educ_years_class i.lfs hhsize_log nchildren_log hhincome_post_log owner [aweight=w11103], a(pid kkz_rek syear) vce(cluster hid)	
esttab, se cells(b(star fmt(%9.3f)) se(par fmt(%9.3f))) star(* 0.10 ** 0.05 *** 0.01) ///
	stats(N r2_a, fmt(%9.0fc %9.3f) labels("Observations" "Adj. R-squared")) ///
	noomitted nobaselevels compress label 	


*** Local engagement
eststo clear
eststo: quietly: reghdfe ties i.move_kreis_yearsto move_kreis i.move_kreis_yearsince ///
	i.agegroup i.marstat i.educ_years_class i.lfs hhsize_log nchildren_log hhincome_post_log owner [aweight=w11103], a(pid kkz_rek syear) vce(cluster hid)
eststo: quietly: reghdfe activism_localpolitics i.move_kreis_yearsto move_kreis i.move_kreis_yearsince ///
	i.agegroup i.marstat i.educ_years_class i.lfs hhsize_log nchildren_log hhincome_post_log owner [aweight=w11103], a(pid kkz_rek syear) vce(cluster hid)
eststo: quietly: reghdfe activism_volunteer i.move_kreis_yearsto move_kreis i.move_kreis_yearsince ///
	i.agegroup i.marstat i.educ_years_class i.lfs hhsize_log nchildren_log hhincome_post_log owner [aweight=w11103], a(pid kkz_rek syear) vce(cluster hid)	
esttab, se cells(b(star fmt(%9.3f)) se(par fmt(%9.3f))) star(* 0.10 ** 0.05 *** 0.01) ///
	stats(N r2_a, fmt(%9.0fc %9.3f) labels("Observations" "Adj. R-squared")) ///
	noomitted nobaselevels compress label 	
	
	
	
	
	
	
	
	
	
*-----------------------------------------------------------------------*
*** Figure 2: Changes in engagement around moves of varying distances ***	
*-----------------------------------------------------------------------*

*** load data
use $mydata/hlueders/CPS_replicationdata.dta, clear


*** Regressions
* political interest
eststo clear
eststo: quietly: reghdfe polinterest i.move_addressHH_prepost ///
	i.agegroup i.marstat i.educ_years_class i.lfs hhsize_log nchildren_log hhincome_post_log owner [aweight=w11103], a(pid kkz_rek syear) vce(cluster hid)
eststo: quietly: reghdfe polinterest i.move_kreis_prepost ///
	i.agegroup i.marstat i.educ_years_class i.lfs hhsize_log nchildren_log hhincome_post_log owner [aweight=w11103], a(pid kkz_rek syear) vce(cluster hid)	
eststo: quietly: reghdfe polinterest i.move_sameland_prepost ///
	i.agegroup i.marstat i.educ_years_class i.lfs hhsize_log nchildren_log hhincome_post_log owner [aweight=w11103], a(pid kkz_rek syear) vce(cluster hid)	
eststo: quietly: reghdfe polinterest i.move_land_prepost ///
	i.agegroup i.marstat i.educ_years_class i.lfs hhsize_log nchildren_log hhincome_post_log owner [aweight=w11103], a(pid kkz_rek syear) vce(cluster hid)		
esttab, se cells(b(star fmt(%9.3f)) se(par fmt(%9.3f))) star(* 0.10 ** 0.05 *** 0.01) ///
	stats(N r2_a, fmt(%9.0fc %9.3f) labels("Observations" "Adj. R-squared")) ///
	noomitted nobaselevels compress label 	
	
* voted in last election
eststo clear
eststo: quietly: reghdfe vote_lastelection i.move_addressHH_prepost ///
	i.agegroup i.marstat i.educ_years_class i.lfs hhsize_log nchildren_log hhincome_post_log owner [aweight=w11103], a(pid kkz_rek syear) vce(cluster hid)
eststo: quietly: reghdfe vote_lastelection i.move_kreis_prepost ///
	i.agegroup i.marstat i.educ_years_class i.lfs hhsize_log nchildren_log hhincome_post_log owner [aweight=w11103], a(pid kkz_rek syear) vce(cluster hid)		
eststo: quietly: reghdfe vote_lastelection i.move_sameland_prepost ///
	i.agegroup i.marstat i.educ_years_class i.lfs hhsize_log nchildren_log hhincome_post_log owner [aweight=w11103], a(pid kkz_rek syear) vce(cluster hid)	
eststo: quietly: reghdfe vote_lastelection i.move_land_prepost ///
	i.agegroup i.marstat i.educ_years_class i.lfs hhsize_log nchildren_log hhincome_post_log owner [aweight=w11103], a(pid kkz_rek syear) vce(cluster hid)	
esttab, se cells(b(star fmt(%9.3f)) se(par fmt(%9.3f))) star(* 0.10 ** 0.05 *** 0.01) ///
	stats(N r2_a, fmt(%9.0fc %9.3f) labels("Observations" "Adj. R-squared")) ///
	noomitted nobaselevels compress label 	

* vote in next election
eststo clear
eststo: quietly: reghdfe vote_nextsunday i.move_addressHH_prepost ///
	i.agegroup i.marstat i.educ_years_class i.lfs hhsize_log nchildren_log hhincome_post_log owner [aweight=w11103], a(pid kkz_rek syear) vce(cluster hid)
eststo: quietly: reghdfe vote_nextsunday i.move_kreis_prepost ///
	i.agegroup i.marstat i.educ_years_class i.lfs hhsize_log nchildren_log hhincome_post_log owner [aweight=w11103], a(pid kkz_rek syear) vce(cluster hid)		
eststo: quietly: reghdfe vote_nextsunday i.move_sameland_prepost ///
	i.agegroup i.marstat i.educ_years_class i.lfs hhsize_log nchildren_log hhincome_post_log owner [aweight=w11103], a(pid kkz_rek syear) vce(cluster hid)	
eststo: quietly: reghdfe vote_nextsunday i.move_land_prepost ///
	i.agegroup i.marstat i.educ_years_class i.lfs hhsize_log nchildren_log hhincome_post_log owner [aweight=w11103], a(pid kkz_rek syear) vce(cluster hid)		
esttab, se cells(b(star fmt(%9.3f)) se(par fmt(%9.3f))) star(* 0.10 ** 0.05 *** 0.01) ///
	stats(N r2_a, fmt(%9.0fc %9.3f) labels("Observations" "Adj. R-squared")) ///
	noomitted nobaselevels compress label 	

* local attachments
eststo clear
eststo: quietly: reghdfe ties i.move_addressHH_prepost ///
	i.agegroup i.marstat i.educ_years_class i.lfs hhsize_log nchildren_log hhincome_post_log owner [aweight=w11103], a(pid kkz_rek syear) vce(cluster hid)
eststo: quietly: reghdfe ties i.move_kreis_prepost ///
	i.agegroup i.marstat i.educ_years_class i.lfs hhsize_log nchildren_log hhincome_post_log owner [aweight=w11103], a(pid kkz_rek syear) vce(cluster hid)		
eststo: quietly: reghdfe ties i.move_sameland_prepost ///
	i.agegroup i.marstat i.educ_years_class i.lfs hhsize_log nchildren_log hhincome_post_log owner [aweight=w11103], a(pid kkz_rek syear) vce(cluster hid)	
eststo: quietly: reghdfe ties i.move_land_prepost ///
	i.agegroup i.marstat i.educ_years_class i.lfs hhsize_log nchildren_log hhincome_post_log owner [aweight=w11103], a(pid kkz_rek syear) vce(cluster hid)	
esttab, se cells(b(star fmt(%9.3f)) se(par fmt(%9.3f))) star(* 0.10 ** 0.05 *** 0.01) ///
	stats(N r2_a, fmt(%9.0fc %9.3f) labels("Observations" "Adj. R-squared")) ///
	noomitted nobaselevels compress label 	

* local politics
eststo clear
eststo: quietly: reghdfe activism_localpolitics i.move_addressHH_prepost ///
	i.agegroup i.marstat i.educ_years_class i.lfs hhsize_log nchildren_log hhincome_post_log owner [aweight=w11103], a(pid kkz_rek syear) vce(cluster hid)
eststo: quietly: reghdfe activism_localpolitics i.move_kreis_prepost ///
	i.agegroup i.marstat i.educ_years_class i.lfs hhsize_log nchildren_log hhincome_post_log owner [aweight=w11103], a(pid kkz_rek syear) vce(cluster hid)		
eststo: quietly: reghdfe activism_localpolitics i.move_sameland_prepost ///
	i.agegroup i.marstat i.educ_years_class i.lfs hhsize_log nchildren_log hhincome_post_log owner [aweight=w11103], a(pid kkz_rek syear) vce(cluster hid)	
eststo: quietly: reghdfe activism_localpolitics i.move_land_prepost ///
	i.agegroup i.marstat i.educ_years_class i.lfs hhsize_log nchildren_log hhincome_post_log owner [aweight=w11103], a(pid kkz_rek syear) vce(cluster hid)	
esttab, se cells(b(star fmt(%9.3f)) se(par fmt(%9.3f))) star(* 0.10 ** 0.05 *** 0.01) ///
	stats(N r2_a, fmt(%9.0fc %9.3f) labels("Observations" "Adj. R-squared")) ///
	noomitted nobaselevels compress label 	

* volunteer
eststo clear
eststo: quietly: reghdfe activism_volunteer i.move_addressHH_prepost ///
	i.agegroup i.marstat i.educ_years_class i.lfs hhsize_log nchildren_log hhincome_post_log owner [aweight=w11103], a(pid kkz_rek syear) vce(cluster hid)
eststo: quietly: reghdfe activism_volunteer i.move_kreis_prepost ///
	i.agegroup i.marstat i.educ_years_class i.lfs hhsize_log nchildren_log hhincome_post_log owner [aweight=w11103], a(pid kkz_rek syear) vce(cluster hid)		
eststo: quietly: reghdfe activism_volunteer i.move_sameland_prepost ///
	i.agegroup i.marstat i.educ_years_class i.lfs hhsize_log nchildren_log hhincome_post_log owner [aweight=w11103], a(pid kkz_rek syear) vce(cluster hid)	
eststo: quietly: reghdfe activism_volunteer i.move_land_prepost ///
	i.agegroup i.marstat i.educ_years_class i.lfs hhsize_log nchildren_log hhincome_post_log owner [aweight=w11103], a(pid kkz_rek syear) vce(cluster hid)	
esttab, se cells(b(star fmt(%9.3f)) se(par fmt(%9.3f))) star(* 0.10 ** 0.05 *** 0.01) ///
	stats(N r2_a, fmt(%9.0fc %9.3f) labels("Observations" "Adj. R-squared")) ///
	noomitted nobaselevels compress label 	






*--------------------------------------*
*** Table A1: Descriptive statistics ***
*--------------------------------------*

*** load data
use $mydata/hlueders/CPS_replicationdata.dta, clear


*** Descriptives at the respondent-level
* identify first year in survey
bysort pid: gen surveyYears = _n

* distribution of move types
tab moveTotal_addressHH if surveyYears == 1
tab moveTotal_kreis if surveyYears == 1
tab moveTotal_land if surveyYears == 1
tab moveTotal_sameland if surveyYears == 1

* distribution of moderators
tab age_old29 if surveyYears == 1
tab abiturSUM if surveyYears == 1
tab collegeSUM if surveyYears == 1


*** Descriptives at the move-level
tab migrant_lowhigh_turnout1 if moveTotal_kreis == 1
tab migrant_lowhigh_ties1 if moveTotal_kreis == 1


*** Descriptives at the respondent-year level
tabstat polinterest, statistics(mean sd)
tabstat vote_lastelection, statistics(mean sd)
tabstat vote_nextsunday, statistics(mean sd)
tabstat ties, statistics(mean sd)
tabstat activism_localpolitics, statistics(mean sd)
tabstat activism_volunteer, statistics(mean sd)








*---------------------------------------------------------------------------*
*** Table A2: Relationship between domestic migration and survey drop-out ***
*---------------------------------------------------------------------------*

*** load data
use $mydata/hlueders/CPS_replicationdata.dta, clear


*** code outcome: dummy of last year in the survey
bysort pid: egen yearMAX = max(syear)
gen left = 0
replace left = 1 if syear == yearMAX
replace left = . if syear == 2020


*** Regressions
eststo clear
eststo: quietly: reghdfe left move_addressHH ///
	i.agegroup i.marstat i.educ_years_class i.lfs hhsize_log nchildren_log hhincome_post_log owner [aweight=w11103], a(pid kkz_rek syear) vce(cluster hid)
eststo: quietly: reghdfe left move_kreis ///
	i.agegroup i.marstat i.educ_years_class i.lfs hhsize_log nchildren_log hhincome_post_log owner [aweight=w11103], a(pid kkz_rek syear) vce(cluster hid)	
eststo: quietly: reghdfe left move_land ///
	i.agegroup i.marstat i.educ_years_class i.lfs hhsize_log nchildren_log hhincome_post_log owner [aweight=w11103], a(pid kkz_rek syear) vce(cluster hid)	
esttab, se cells(b(star fmt(%9.3f)) se(par fmt(%9.3f))) star(* 0.10 ** 0.05 *** 0.01) ///
	stats(N r2_a, fmt(%9.0fc %9.3f) labels("Observations" "Adj. R-squared")) ///
	noomitted nobaselevels compress label 






*---------------------------------------------------------------------------*
*** Table A3: Change in engagement around a move, by distance of the move ***
*---------------------------------------------------------------------------*

*** see Figure 2 above ***








*-----------------------------------------------*
*** Table A4: Engagement after a move, by age ***
*-----------------------------------------------*

*** load data
use $mydata/hlueders/CPS_replicationdata.dta, clear


*** Regressions
* National engagement
eststo clear
eststo: quietly: reghdfe polinterest i.move_kreis_post##i.age_old29 ///
	i.agegroup i.marstat i.lfs hhsize_log nchildren_log hhincome_post_log owner ///
	[aweight=w11103], a(pid kkz_rek syear) vce(cluster hid)
eststo: quietly: reghdfe vote_lastelection i.move_kreis_post##i.age_old29 ///
	i.agegroup i.marstat i.lfs hhsize_log nchildren_log hhincome_post_log owner ///
	[aweight=w11103], a(pid kkz_rek syear) vce(cluster hid)		
eststo: quietly: reghdfe vote_nextsunday i.move_kreis_post##i.age_old29 ///
	i.agegroup i.marstat i.lfs hhsize_log nchildren_log hhincome_post_log owner ///
	[aweight=w11103], a(pid kkz_rek syear) vce(cluster hid)			
esttab, se cells(b(star fmt(%9.3f)) se(par fmt(%9.3f))) star(* 0.10 ** 0.05 *** 0.01) ///
	stats(N r2_a, fmt(%9.0fc %9.3f) labels("Observations" "Adj. R-squared")) ///
	noomitted nobaselevels compress label 

* Local engagement
eststo clear
eststo: quietly: reghdfe ties i.move_kreis_post##i.age_old29 ///
	i.agegroup i.marstat i.lfs hhsize_log nchildren_log hhincome_post_log owner ///
	[aweight=w11103], a(pid kkz_rek syear) vce(cluster hid)
eststo: quietly: reghdfe activism_localpolitics i.move_kreis_post##i.age_old29 ///
	i.agegroup i.marstat i.lfs hhsize_log nchildren_log hhincome_post_log owner ///
	[aweight=w11103], a(pid kkz_rek syear) vce(cluster hid)		
eststo: quietly: reghdfe activism_volunteer i.move_kreis_post##i.age_old29 ///
	i.agegroup i.marstat i.lfs hhsize_log nchildren_log hhincome_post_log owner ///
	[aweight=w11103], a(pid kkz_rek syear) vce(cluster hid)			
esttab, se cells(b(star fmt(%9.3f)) se(par fmt(%9.3f))) star(* 0.10 ** 0.05 *** 0.01) ///
	stats(N r2_a, fmt(%9.0fc %9.3f) labels("Observations" "Adj. R-squared")) ///
	noomitted nobaselevels compress label 






	
*----------------------------------------------------------------------------------------*	
*** Figure A3 and Table A5: Changes in engagement around a move, by level of education ***
*----------------------------------------------------------------------------------------*

*** load data
use $mydata/hlueders/CPS_replicationdata.dta, clear


*** Political interest
* by Abitur no/yes
eststo clear
eststo: quietly: reghdfe polinterest i.move_kreis_prepost ///
	i.agegroup i.marstat i.educ_years_class i.lfs hhsize_log nchildren_log hhincome_post_log owner if abiturSUM == 0 [aweight=w11103], a(pid kkz_rek syear) vce(cluster hid)
eststo: quietly: reghdfe polinterest i.move_kreis_prepost ///
	i.agegroup i.marstat i.educ_years_class i.lfs hhsize_log nchildren_log hhincome_post_log owner if abiturSUM == 1 [aweight=w11103], a(pid kkz_rek syear) vce(cluster hid)	
eststo: quietly: reghdfe polinterest i.move_kreis_prepost##i.abiturSUM ///
	i.agegroup i.marstat i.educ_years_class i.lfs hhsize_log nchildren_log hhincome_post_log owner [aweight=w11103], a(pid kkz_rek syear) vce(cluster hid)
esttab, se cells(b(star fmt(%9.3f)) se(par fmt(%9.3f))) star(* 0.10 ** 0.05 *** 0.01) ///
	stats(N r2_a, fmt(%9.0fc %9.3f) labels("Observations" "Adj. R-squared")) ///
	noomitted nobaselevels compress label 
	
* by college degree no/yes
eststo clear
eststo: quietly: reghdfe polinterest i.move_kreis_prepost ///
	i.agegroup i.marstat i.educ_years_class i.lfs hhsize_log nchildren_log hhincome_post_log owner if collegeSUM == 0 [aweight=w11103], a(pid kkz_rek syear) vce(cluster hid)
eststo: quietly: reghdfe polinterest i.move_kreis_prepost ///
	i.agegroup i.marstat i.educ_years_class i.lfs hhsize_log nchildren_log hhincome_post_log owner if collegeSUM == 1 [aweight=w11103], a(pid kkz_rek syear) vce(cluster hid)	
eststo: quietly: reghdfe polinterest i.move_kreis_prepost##i.collegeSUM ///
	i.agegroup i.marstat i.educ_years_class i.lfs hhsize_log nchildren_log hhincome_post_log owner [aweight=w11103], a(pid kkz_rek syear) vce(cluster hid)
esttab, se cells(b(star fmt(%9.3f)) se(par fmt(%9.3f))) star(* 0.10 ** 0.05 *** 0.01) ///
	stats(N r2_a, fmt(%9.0fc %9.3f) labels("Observations" "Adj. R-squared")) ///
	noomitted nobaselevels compress label 	


*** Voted in last election
* by Abitur no/yes
eststo clear
eststo: quietly: reghdfe vote_lastelection i.move_kreis_prepost ///
	i.agegroup i.marstat i.educ_years_class i.lfs hhsize_log nchildren_log hhincome_post_log owner if abiturSUM == 0 [aweight=w11103], a(pid kkz_rek syear) vce(cluster hid)
eststo: quietly: reghdfe vote_lastelection i.move_kreis_prepost ///
	i.agegroup i.marstat i.educ_years_class i.lfs hhsize_log nchildren_log hhincome_post_log owner if abiturSUM == 1 [aweight=w11103], a(pid kkz_rek syear) vce(cluster hid)	
eststo: quietly: reghdfe vote_lastelection i.move_kreis_prepost##i.abiturSUM ///
	i.agegroup i.marstat i.educ_years_class i.lfs hhsize_log nchildren_log hhincome_post_log owner [aweight=w11103], a(pid kkz_rek syear) vce(cluster hid)
esttab, se cells(b(star fmt(%9.3f)) se(par fmt(%9.3f))) star(* 0.10 ** 0.05 *** 0.01) ///
	stats(N r2_a, fmt(%9.0fc %9.3f) labels("Observations" "Adj. R-squared")) ///
	noomitted nobaselevels compress label 
	
* by college degree no/yes
eststo clear
eststo: quietly: reghdfe vote_lastelection i.move_kreis_prepost ///
	i.agegroup i.marstat i.educ_years_class i.lfs hhsize_log nchildren_log hhincome_post_log owner if collegeSUM == 0 [aweight=w11103], a(pid kkz_rek syear) vce(cluster hid)
eststo: quietly: reghdfe vote_lastelection i.move_kreis_prepost ///
	i.agegroup i.marstat i.educ_years_class i.lfs hhsize_log nchildren_log hhincome_post_log owner if collegeSUM == 1 [aweight=w11103], a(pid kkz_rek syear) vce(cluster hid)	
eststo: quietly: reghdfe vote_lastelection i.move_kreis_prepost##i.collegeSUM ///
	i.agegroup i.marstat i.educ_years_class i.lfs hhsize_log nchildren_log hhincome_post_log owner [aweight=w11103], a(pid kkz_rek syear) vce(cluster hid)
esttab, se cells(b(star fmt(%9.3f)) se(par fmt(%9.3f))) star(* 0.10 ** 0.05 *** 0.01) ///
	stats(N r2_a, fmt(%9.0fc %9.3f) labels("Observations" "Adj. R-squared")) ///
	noomitted nobaselevels compress label 


*** Vote in next election
* by Abitur no/yes
eststo clear
eststo: quietly: reghdfe vote_nextsunday i.move_kreis_prepost ///
	i.agegroup i.marstat i.educ_years_class i.lfs hhsize_log nchildren_log hhincome_post_log owner if abiturSUM == 0 [aweight=w11103], a(pid kkz_rek syear) vce(cluster hid)
eststo: quietly: reghdfe vote_nextsunday i.move_kreis_prepost ///
	i.agegroup i.marstat i.educ_years_class i.lfs hhsize_log nchildren_log hhincome_post_log owner if abiturSUM == 1 [aweight=w11103], a(pid kkz_rek syear) vce(cluster hid)	
eststo: quietly: reghdfe vote_nextsunday i.move_kreis_prepost##i.abiturSUM ///
	i.agegroup i.marstat i.educ_years_class i.lfs hhsize_log nchildren_log hhincome_post_log owner [aweight=w11103], a(pid kkz_rek syear) vce(cluster hid)
esttab, se cells(b(star fmt(%9.3f)) se(par fmt(%9.3f))) star(* 0.10 ** 0.05 *** 0.01) ///
	stats(N r2_a, fmt(%9.0fc %9.3f) labels("Observations" "Adj. R-squared")) ///
	noomitted nobaselevels compress label 
	
* by college degree no/yes
eststo clear
eststo: quietly: reghdfe vote_nextsunday i.move_kreis_prepost ///
	i.agegroup i.marstat i.educ_years_class i.lfs hhsize_log nchildren_log hhincome_post_log owner if collegeSUM == 0 [aweight=w11103], a(pid kkz_rek syear) vce(cluster hid)
eststo: quietly: reghdfe vote_nextsunday i.move_kreis_prepost ///
	i.agegroup i.marstat i.educ_years_class i.lfs hhsize_log nchildren_log hhincome_post_log owner if collegeSUM == 1 [aweight=w11103], a(pid kkz_rek syear) vce(cluster hid)	
eststo: quietly: reghdfe vote_nextsunday i.move_kreis_prepost##i.collegeSUM ///
	i.agegroup i.marstat i.educ_years_class i.lfs hhsize_log nchildren_log hhincome_post_log owner [aweight=w11103], a(pid kkz_rek syear) vce(cluster hid)
esttab, se cells(b(star fmt(%9.3f)) se(par fmt(%9.3f))) star(* 0.10 ** 0.05 *** 0.01) ///
	stats(N r2_a, fmt(%9.0fc %9.3f) labels("Observations" "Adj. R-squared")) ///
	noomitted nobaselevels compress label 


*** Local attachments
* by Abitur no/yes
eststo clear
eststo: quietly: reghdfe ties i.move_kreis_prepost ///
	i.agegroup i.marstat i.educ_years_class i.lfs hhsize_log nchildren_log hhincome_post_log owner if abiturSUM == 0 [aweight=w11103], a(pid kkz_rek syear) vce(cluster hid)
eststo: quietly: reghdfe ties i.move_kreis_prepost ///
	i.agegroup i.marstat i.educ_years_class i.lfs hhsize_log nchildren_log hhincome_post_log owner if abiturSUM == 1 [aweight=w11103], a(pid kkz_rek syear) vce(cluster hid)	
eststo: quietly: reghdfe ties i.move_kreis_prepost##i.abiturSUM ///
	i.agegroup i.marstat i.educ_years_class i.lfs hhsize_log nchildren_log hhincome_post_log owner [aweight=w11103], a(pid kkz_rek syear) vce(cluster hid)
esttab, se cells(b(star fmt(%9.3f)) se(par fmt(%9.3f))) star(* 0.10 ** 0.05 *** 0.01) ///
	stats(N r2_a, fmt(%9.0fc %9.3f) labels("Observations" "Adj. R-squared")) ///
	noomitted nobaselevels compress label 
	
* by college degree no/yes
eststo clear
eststo: quietly: reghdfe ties i.move_kreis_prepost ///
	i.agegroup i.marstat i.educ_years_class i.lfs hhsize_log nchildren_log hhincome_post_log owner if collegeSUM == 0 [aweight=w11103], a(pid kkz_rek syear) vce(cluster hid)
eststo: quietly: reghdfe ties i.move_kreis_prepost ///
	i.agegroup i.marstat i.educ_years_class i.lfs hhsize_log nchildren_log hhincome_post_log owner if collegeSUM == 1 [aweight=w11103], a(pid kkz_rek syear) vce(cluster hid)	
eststo: quietly: reghdfe ties i.move_kreis_prepost##i.collegeSUM ///
	i.agegroup i.marstat i.educ_years_class i.lfs hhsize_log nchildren_log hhincome_post_log owner [aweight=w11103], a(pid kkz_rek syear) vce(cluster hid)
esttab, se cells(b(star fmt(%9.3f)) se(par fmt(%9.3f))) star(* 0.10 ** 0.05 *** 0.01) ///
	stats(N r2_a, fmt(%9.0fc %9.3f) labels("Observations" "Adj. R-squared")) ///
	noomitted nobaselevels compress label 


*** Local politics
* by Abitur no/yes
eststo clear
eststo: quietly: reghdfe activism_localpolitics i.move_kreis_prepost ///
	i.agegroup i.marstat i.educ_years_class i.lfs hhsize_log nchildren_log hhincome_post_log owner if abiturSUM == 0 [aweight=w11103], a(pid kkz_rek syear) vce(cluster hid)
eststo: quietly: reghdfe activism_localpolitics i.move_kreis_prepost ///
	i.agegroup i.marstat i.educ_years_class i.lfs hhsize_log nchildren_log hhincome_post_log owner if abiturSUM == 1 [aweight=w11103], a(pid kkz_rek syear) vce(cluster hid)	
eststo: quietly: reghdfe activism_localpolitics i.move_kreis_prepost##i.abiturSUM ///
	i.agegroup i.marstat i.educ_years_class i.lfs hhsize_log nchildren_log hhincome_post_log owner [aweight=w11103], a(pid kkz_rek syear) vce(cluster hid)
esttab, se cells(b(star fmt(%9.3f)) se(par fmt(%9.3f))) star(* 0.10 ** 0.05 *** 0.01) ///
	stats(N r2_a, fmt(%9.0fc %9.3f) labels("Observations" "Adj. R-squared")) ///
	noomitted nobaselevels compress label 
	
* by college degree no/yes
eststo clear
eststo: quietly: reghdfe activism_localpolitics i.move_kreis_prepost ///
	i.agegroup i.marstat i.educ_years_class i.lfs hhsize_log nchildren_log hhincome_post_log owner if collegeSUM == 0 [aweight=w11103], a(pid kkz_rek syear) vce(cluster hid)
eststo: quietly: reghdfe activism_localpolitics i.move_kreis_prepost ///
	i.agegroup i.marstat i.educ_years_class i.lfs hhsize_log nchildren_log hhincome_post_log owner if collegeSUM == 1 [aweight=w11103], a(pid kkz_rek syear) vce(cluster hid)	
eststo: quietly: reghdfe activism_localpolitics i.move_kreis_prepost##i.collegeSUM ///
	i.agegroup i.marstat i.educ_years_class i.lfs hhsize_log nchildren_log hhincome_post_log owner [aweight=w11103], a(pid kkz_rek syear) vce(cluster hid)
esttab, se cells(b(star fmt(%9.3f)) se(par fmt(%9.3f))) star(* 0.10 ** 0.05 *** 0.01) ///
	stats(N r2_a, fmt(%9.0fc %9.3f) labels("Observations" "Adj. R-squared")) ///
	noomitted nobaselevels compress label 


*** Volunteer
* by Abitur no/yes
eststo clear
eststo: quietly: reghdfe activism_volunteer i.move_kreis_prepost ///
	i.agegroup i.marstat i.educ_years_class i.lfs hhsize_log nchildren_log hhincome_post_log owner if abiturSUM == 0 [aweight=w11103], a(pid kkz_rek syear) vce(cluster hid)
eststo: quietly: reghdfe activism_volunteer i.move_kreis_prepost ///
	i.agegroup i.marstat i.educ_years_class i.lfs hhsize_log nchildren_log hhincome_post_log owner if abiturSUM == 1 [aweight=w11103], a(pid kkz_rek syear) vce(cluster hid)	
eststo: quietly: reghdfe activism_volunteer i.move_kreis_prepost##i.abiturSUM ///
	i.agegroup i.marstat i.educ_years_class i.lfs hhsize_log nchildren_log hhincome_post_log owner [aweight=w11103], a(pid kkz_rek syear) vce(cluster hid)
esttab, se cells(b(star fmt(%9.3f)) se(par fmt(%9.3f))) star(* 0.10 ** 0.05 *** 0.01) ///
	stats(N r2_a, fmt(%9.0fc %9.3f) labels("Observations" "Adj. R-squared")) ///
	noomitted nobaselevels compress label 
	
* by college degree no/yes
eststo clear
eststo: quietly: reghdfe activism_volunteer i.move_kreis_prepost ///
	i.agegroup i.marstat i.educ_years_class i.lfs hhsize_log nchildren_log hhincome_post_log owner if collegeSUM == 0 [aweight=w11103], a(pid kkz_rek syear) vce(cluster hid)
eststo: quietly: reghdfe activism_volunteer i.move_kreis_prepost ///
	i.agegroup i.marstat i.educ_years_class i.lfs hhsize_log nchildren_log hhincome_post_log owner if collegeSUM == 1 [aweight=w11103], a(pid kkz_rek syear) vce(cluster hid)	
eststo: quietly: reghdfe activism_volunteer i.move_kreis_prepost##i.collegeSUM ///
	i.agegroup i.marstat i.educ_years_class i.lfs hhsize_log nchildren_log hhincome_post_log owner [aweight=w11103], a(pid kkz_rek syear) vce(cluster hid)
esttab, se cells(b(star fmt(%9.3f)) se(par fmt(%9.3f))) star(* 0.10 ** 0.05 *** 0.01) ///
	stats(N r2_a, fmt(%9.0fc %9.3f) labels("Observations" "Adj. R-squared")) ///
	noomitted nobaselevels compress label 







*------------------------------------------------------*
*** Table A13: Little evidence of contextual effects ***
*------------------------------------------------------*

*** load data
use $mydata/hlueders/CPS_replicationdata.dta, clear



*** Regressions 1: Context is measured using federal turnout
* National engagement
eststo clear
eststo: quietly: reghdfe polinterest i.move_kreis_post##i.migrant_lowhigh_turnout1 ///
	i.agegroup i.marstat i.educ_years_class i.lfs hhsize_log nchildren_log hhincome_post_log owner ///
	[aweight=w11103], a(pid kkz_rek syear) vce(cluster hid)	
eststo: quietly: reghdfe vote_lastelection i.move_kreis_post##i.migrant_lowhigh_turnout1 ///
	i.agegroup i.marstat i.educ_years_class i.lfs hhsize_log nchildren_log hhincome_post_log owner ///
	[aweight=w11103], a(pid kkz_rek syear) vce(cluster hid)	
eststo: quietly: reghdfe vote_nextsunday i.move_kreis_post##i.migrant_lowhigh_turnout1 ///
	i.agegroup i.marstat i.educ_years_class i.lfs hhsize_log nchildren_log hhincome_post_log owner ///
	[aweight=w11103], a(pid kkz_rek syear) vce(cluster hid)		
esttab, se cells(b(star fmt(%9.3f)) se(par fmt(%9.3f))) star(* 0.10 ** 0.05 *** 0.01) ///
	stats(N r2_a, fmt(%9.0fc %9.3f) labels("Observations" "Adj. R-squared")) ///
	noomitted nobaselevels compress label 	
	
* Local engagement
eststo clear
eststo: quietly: reghdfe ties i.move_kreis_post##i.migrant_lowhigh_turnout1 ///
	i.agegroup i.marstat i.educ_years_class i.lfs hhsize_log nchildren_log hhincome_post_log owner ///
	[aweight=w11103], a(pid kkz_rek syear) vce(cluster hid)	
eststo: quietly: reghdfe activism_localpolitics i.move_kreis_post##i.migrant_lowhigh_turnout1 ///
	i.agegroup i.marstat i.educ_years_class i.lfs hhsize_log nchildren_log hhincome_post_log owner ///
	[aweight=w11103], a(pid kkz_rek syear) vce(cluster hid)	
eststo: quietly: reghdfe activism_volunteer i.move_kreis_post##i.migrant_lowhigh_turnout1 ///
	i.agegroup i.marstat i.educ_years_class i.lfs hhsize_log nchildren_log hhincome_post_log owner ///
	[aweight=w11103], a(pid kkz_rek syear) vce(cluster hid)		
esttab, se cells(b(star fmt(%9.3f)) se(par fmt(%9.3f))) star(* 0.10 ** 0.05 *** 0.01) ///
	stats(N r2_a, fmt(%9.0fc %9.3f) labels("Observations" "Adj. R-squared")) ///
	noomitted nobaselevels compress label 	
	
	
	
	
*** Regressions 2: Context is measured using local attachments	
* National engagement
eststo clear
eststo: quietly: reghdfe polinterest i.move_kreis_post##i.migrant_lowhigh_ties1 ///
	i.agegroup i.marstat i.educ_years_class i.lfs hhsize_log nchildren_log hhincome_post_log owner ///
	[aweight=w11103], a(pid kkz_rek syear) vce(cluster hid)	
eststo: quietly: reghdfe vote_lastelection i.move_kreis_post##i.migrant_lowhigh_ties1 ///
	i.agegroup i.marstat i.educ_years_class i.lfs hhsize_log nchildren_log hhincome_post_log owner ///
	[aweight=w11103], a(pid kkz_rek syear) vce(cluster hid)	
eststo: quietly: reghdfe vote_nextsunday i.move_kreis_post##i.migrant_lowhigh_ties1 ///
	i.agegroup i.marstat i.educ_years_class i.lfs hhsize_log nchildren_log hhincome_post_log owner ///
	[aweight=w11103], a(pid kkz_rek syear) vce(cluster hid)		
esttab, se cells(b(star fmt(%9.3f)) se(par fmt(%9.3f))) star(* 0.10 ** 0.05 *** 0.01) ///
	stats(N r2_a, fmt(%9.0fc %9.3f) labels("Observations" "Adj. R-squared")) ///
	noomitted nobaselevels compress label 	
	
* Local engagement
eststo clear
eststo: quietly: reghdfe ties i.move_kreis_post##i.migrant_lowhigh_ties1 ///
	i.agegroup i.marstat i.educ_years_class i.lfs hhsize_log nchildren_log hhincome_post_log owner ///
	[aweight=w11103], a(pid kkz_rek syear) vce(cluster hid)	
eststo: quietly: reghdfe activism_localpolitics i.move_kreis_post##i.migrant_lowhigh_ties1 ///
	i.agegroup i.marstat i.educ_years_class i.lfs hhsize_log nchildren_log hhincome_post_log owner ///
	[aweight=w11103], a(pid kkz_rek syear) vce(cluster hid)	
eststo: quietly: reghdfe activism_volunteer i.move_kreis_post##i.migrant_lowhigh_ties1 ///
	i.agegroup i.marstat i.educ_years_class i.lfs hhsize_log nchildren_log hhincome_post_log owner ///
	[aweight=w11103], a(pid kkz_rek syear) vce(cluster hid)		
esttab, se cells(b(star fmt(%9.3f)) se(par fmt(%9.3f))) star(* 0.10 ** 0.05 *** 0.01) ///
	stats(N r2_a, fmt(%9.0fc %9.3f) labels("Observations" "Adj. R-squared")) ///
	noomitted nobaselevels compress label 	

































	
	
	
	
	
	
	





